package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.VoiceUser;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.Date;

@Service
public class VoiceUserApiImpl implements VoiceUserApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存 publishId 到用户个人语音表
     * @param userId
     * @param publishId
     */
    @Override
    public void saveVoice(Integer userId, ObjectId publishId) {

        VoiceUser voiceUser = new VoiceUser();
        Date date = new Date();
        voiceUser.setCreated(date.getTime());
        voiceUser.setPublishId(publishId);

        String key = "tanhua_voice_"+userId;
        mongoTemplate.save(voiceUser,key);
    }
}
